//
//  ZYVideoNetView.m
//  视频播放
//
//  Created by zhangzhenyun on 2018/8/1.
//  Copyright © 2018年 Beijing Youjiu Network. All rights reserved.
//

#import "ZYVideoNoNetView.h"

@interface ZYVideoNoNetView ()
@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) UILabel *infoLab;
@property (nonatomic, strong) UIButton *refreshBtn;

@end

@implementation ZYVideoNoNetView
- (instancetype)init {
    if (self = [super init]) {
        [self setupViews];
    }
    return self;
}
- (void)setupViews {
    [self addSubview:self.backView];
    [self addSubview:self.containerView];
    [self.containerView addSubview:self.infoLab];
    [self.containerView addSubview:self.refreshBtn];
    [self setupLayout];
}
#pragma mark - target
- (void)refreshAction:(UIButton *)btn {
    if (self.refreshBlock) {
        self.refreshBlock(btn);
    }
}
#pragma mark - layout
- (void)setupLayout {
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(Fix375(150), Fix375(80)));
    }];
    [self.infoLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.containerView);
        make.centerX.equalTo(self.containerView);
    }];
    [self.refreshBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.infoLab.mas_bottom).offset(Fix375(36));
        make.centerX.equalTo(self.infoLab);
        make.size.mas_equalTo(CGSizeMake(Fix375(90), Fix375(30)));
    }];
}
#pragma mark - getter
-(UIView *)backView {
    if (_backView == nil) {
        _backView = [[UIView alloc] init];
        _backView.backgroundColor = [UIColor blackColor];
        _backView.alpha = 0.6;
    }
    return _backView;
}
-(UIView *)containerView {
    if (_containerView == nil) {
        _containerView = [[UIView alloc] init];
        _containerView.backgroundColor = [UIColor blackColor];
        _containerView.alpha = 0.6;
    }
    return _containerView;
}
-(UILabel *)infoLab {
    if (_infoLab == nil) {
        _infoLab = [[UILabel alloc] init];
        _infoLab.text = @"网络未连接,请检查网络设置";
        _infoLab.font = RMFont(10);
        _infoLab.textColor = [UIColor whiteColor];
    }
    return _infoLab;
}
-(UIButton *)refreshBtn {
    if (_refreshBtn == nil) {
        _refreshBtn = [[UIButton alloc] init];
        _refreshBtn.backgroundColor = col_3296FA;
        _refreshBtn.layer.cornerRadius = Fix375(15);
        _refreshBtn.layer.masksToBounds = YES;
        [_refreshBtn setTitle:@"刷新重试" forState:UIControlStateNormal];
        _refreshBtn.titleLabel.font = RMFont(12);
        [_refreshBtn addTarget:self action:@selector(refreshAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _refreshBtn;
}

@end
